// Modules to control application life and create native browser window
const { app, BrowserWindow, Menu } = require("electron");
const { getOpenFormLogin } = require("./auto_start");
const { Config } = require("./config");
const { store } = require("./config");
const { createMainWindow, createRest } = require("./window");
const { setRest, restWindow } = require("./rest");
const { setEye } = require("./eye");
const { enableAutoStart } = require("./auto_start");

if (store.get(Config.enableAutoStartKEY) == null) {
  enableAutoStart();
}

app.whenReady().then(() => {
  setEye();
  setRest();
  Menu.setApplicationMenu(
    Menu.buildFromTemplate([
      {
        label: "eye",
        role: "window",
        submenu: [
          {
            label: "关闭",
            role: "close",
          },
        ],
      },
    ])
  );
  app.whenReady().then(() => {
    if (!getOpenFormLogin()) {
        createMainWindow();
    }
  });
  app.on("activate", function () {
    if (BrowserWindow.getAllWindows().length === 0) createMainWindow();
  });
  app.on('window-all-closed', () => {
    app.dock.hide()
  })
});

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
// app.on('window-all-closed', function () {
//   if (process.platform !== 'darwin') app.quit()
// })
app.on("window-all-closed", (e) => e.preventDefault());

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
